package commands;

import core.GameObject;

/**
 * A Command to add a new Card to the game, based on an AbstractCard prototype
 */
public abstract class NewAttributeCommand extends Command
{
	/**
	 * Creates a generic <code>NewCardCommand</code> with <code>set = name = zone = null</code>.
	 */
	public NewAttributeCommand() {
		this(null, null);
	}

	/**
	 * Creates a NewCardCommand to add a card from the given set to the given zone
	 * @param set the set containing the card (see <code>CardParser</code>)
	 * @param name the name of the card
	 * @param zone the Zone to which the card should be added
	 */
	public NewAttributeCommand(String name, GameObject parent) {
		setName(name);
		setParent(parent);
	}

	/**
	 * Looks up the AbstractCard prototype in the provided set by the provided name. 
	 * If it is found, initializes a new Card and stores it in the provided Zone.
	 */
	public net.StateUpdate execute() throws CommandException {
		net.StateUpdate stateUpdate = super.execute();
		stateUpdate.addChange(new net.ChildAddition(parent, "attribute", newAttribute = createAttribute(name)));
		return stateUpdate;
	}
		
	public String toString() {
		return "NewAttributeCommand: name=" + name + " parent=" + parent;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public GameObject getParent() {
		return parent;
	}

	public void setParent(GameObject parent) {
		this.parent = parent;
	}

	public String getMessage() {
		return "new attribute " + util.Util.prettyPrint(newAttribute) + " of " + util.Util.prettyPrint(parent);
	}

	protected abstract core.Attribute createAttribute(String name);

	private core.Attribute newAttribute;
	private String name;
	private GameObject parent;
}